package com.sgb.kjwl.viewmodel.machine;

import androidx.databinding.ObservableField;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.repository.MachineRepertory;
import com.sgb.kjwl.view.ui.activity.leaseAsk.MachineListActivity3;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MLog;

import java.util.List;

import io.reactivex.functions.Consumer;

public class MachineListModel3 extends BaseViewModel {
    public ObservableField<String> areaCode = new ObservableField<>("");
    private MachineListActivity3 activity;
    private MachineRepertory repertory;

    public MachineListModel3(MachineListActivity3 activity, MachineRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
        areaCode.set(repertory.getAreaCode());
    }

    public void getFilterTypeModel() {
        repertory.getMachineFilterType()
                .subscribe(new Consumer<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void accept(BaseEntity<List<DictEntity3>> listBaseEntity) throws Exception {
                        if (listBaseEntity.getState().equals(AppConstant.REQEUST_SECCUESS)) {
                            activity.showTypeView(listBaseEntity.getData());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        MLog.d(AppConstant.API_LOG, "error " + throwable.getMessage());
                    }
                });
    }
}
